package com.itheima.ydd.commom;


import com.itheima.ydd.entity.SysUser;

//基于ThreadLocal的工具类，用于设置和获取当前登录用户的id
public class BaseContext {

    private static  ThreadLocal<SysUser> threadLocal = new ThreadLocal<>();

    //设置id属性值
    public static void setCurrentId(SysUser user){
        threadLocal.set(user);
    }

    //获取id
    public static SysUser getCurrentId(){
        return threadLocal.get();
    }

    //获取用户id
    public static String getUserId(){return threadLocal.get().getId();}

    //移除当前线程的所有资源
    public static void  remove(){
        threadLocal.remove();
    }
}
